package com.ylbh.modules.storereturn.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ylbh.common.pojo.storereturn.dto.StoreReturnDTO;
import com.ylbh.common.pojo.storereturn.vo.StoreReturnVO;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.modules.storereturn.entity.ShoppingStoreReturn;
import com.ylbh.modules.storereturn.mapper.ShoppingStoreReturnMapper;
import com.ylbh.modules.storereturn.service.ShoppingStoreReturnService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class ShoppingStoreReturnServiceImpl extends ServiceImpl<ShoppingStoreReturnMapper, ShoppingStoreReturn> implements ShoppingStoreReturnService {

    @Autowired
    private ShoppingStoreReturnMapper shoppingStoreReturnMapper;

    /**
     * 联盟店退换货列表
     * @param pageDTO
     * @return
     */
    @Override
    public PageUtils queryStoreReturnList(StoreReturnDTO pageDTO) {
        Page<Object> page = new Page<>(pageDTO.getPage(), pageDTO.getLimit());
        List<ShoppingStoreReturn> list = shoppingStoreReturnMapper.selectStoreReturnList(pageDTO, page);
        return new PageUtils(new Page<ShoppingStoreReturn>().setTotal(page.getTotal()).setRecords(list));
    }

    /**
     * 联盟店退换货详情
     * @param returnId
     * @return
     */
    @Override
    public StoreReturnVO getStoreReturnById(String returnId) {
        StoreReturnVO vo = shoppingStoreReturnMapper.selectStoreReturnById(returnId);
        if (!StringUtils.isEmpty(vo.getApplyReturnImages())) {
            String[] img = vo.getApplyReturnImages().split(",");
            vo.setImg(Arrays.asList(img));
        }
        return vo;
    }
}
